package cn.hftoday.org;

import java.util.*;
import cn.hftoday.util.*;
import cn.hftoday.db.*;
import cn.hftoday.core.*;

/**
 * organization type
 * @author lane.cn@gmail.com
 *
 */
public class OrganizationType {
	private String id;
	private String companyId;
	private String name;
	private String icon;
	
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}
	
	/**
	 * company
	 * @return
	 */
	public Company getCompany() {
		return (Company)Mapper.getInstance().queryForObject("SelectCompanyById", companyId);
	}
	
	/**
	 * company
	 * @param company
	 */
	public void setCompany(Company company) {
		if (company == null) {
			companyId = null;
		}
		else {
			companyId = company.getId();
		}
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getIcon() {
		return icon;
	}
	
	public void setIcon(String icon) {
		this.icon = icon;
	}

	private static void _select(Object object, RecordSet rs, int i) {
		OrganizationType o = (OrganizationType)object;
		o.id = rs.getItem(i, "f_id");
		o.companyId = rs.getItem(i, "f_company");
		o.name = rs.getItem(i, "f_name");
		o.icon = rs.getItem(i, "f_icon");
	}
	
	private static String _insert(Object object, String sql) {
		OrganizationType o = (OrganizationType)object;
		return StringParser.formatSql(sql, 
			o.id,
			o.companyId,
			o.name,
			o.icon
		);
	}
	
	private static String _update(Object object, String sql) {
		OrganizationType o = (OrganizationType)object;
		return StringParser.formatSql(sql, 
			o.id,
			o.companyId,
			o.name,
			o.icon
		);
	}
	
	private static String _delete(Object object, String sql) {
		OrganizationType o = (OrganizationType)object;
		return StringParser.formatSql(sql, 
			o.id
		);
	}
}
